package cn.edu.scau.cmi.zhengweixin.adapter;

import java.net.URL;
import java.util.ResourceBundle;

import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.ChoiceBox;
import javafx.scene.control.TextArea;
import javafx.scene.input.MouseEvent;

public class AdapterController {

    @FXML
    private ResourceBundle resources;

    @FXML
    private URL location;

    @FXML
    private ChoiceBox<String> myChoiceBox;

    @FXML
    private TextArea outputTextArea;

    @FXML
    private Button myButton;
    
    @FXML
    void output(ActionEvent event) {
    	Adaptee adaptee = new Adaptee();
    	String message = "请选择输出电压";
    	switch(myChoiceBox.getSelectionModel().getSelectedIndex()) {
			case 0:{
				message = "original voltage: " + adaptee.getVoltage();
				break;
			}
			case 1:{
				Target classTarget = new AdapterOfClass();
				message = adaptee.getVoltage() + " change to " + classTarget.outputVoltage() + " by AdapterOfClass";
				break;
			}
			case 2:{
				Target objectTarget = new AdapterOfObject(adaptee);
				message = adaptee.getVoltage() + " change to " + objectTarget.outputVoltage() + " by AdapterOfObject";
				break;
			}
			default:
				break;
    	}
		outputTextArea.appendText(message + "\n");
    }
    
    @FXML
    void selectType(MouseEvent event) {
    	myChoiceBox.setItems(FXCollections.observableArrayList("原始电压", "类适配电压", "对象适配电压"));	
    }

    @FXML
    void initialize() {
        assert myChoiceBox != null : "fx:id=\"myChoiceBox\" was not injected: check your FXML file 'Adapter.fxml'.";
        assert outputTextArea != null : "fx:id=\"outputTextArea\" was not injected: check your FXML file 'Adapter.fxml'.";


    }

}
